package com.mengtian_tech.tju.dataquery.api.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mengtian_tech.tju.dataquery.api.util.ResponseUtil;




@Controller
@RequestMapping("/api/logout")
public class LogoutController {
	
	@Autowired
	private Environment env;
	
	@RequestMapping("")
	@ResponseBody
	public Object logout(HttpServletRequest request,HttpServletResponse response,HttpSession session) throws IOException {
		session.invalidate();
    	String service = env.getProperty("cas.client-host-url");
    	String loginOutUrl= env.getProperty("other.server-logout-url");
		
	    // ids的退出地址，ids6.wisedu.com为ids的域名  authserver为ids的上下文，logout为固定值
	    // service后面带的参数为应用的访问地址，需要使用URLEncoder进行编码
	    String redirectURL=loginOutUrl+"?service="+service+"/cas/";
		
		
	    return ResponseUtil.ok(redirectURL);
	}
}
